package view.transitions;

import java.awt.Graphics;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;

public class CopyOfDoorOpen extends Animator {

	private BufferedImage	buffer;
	public CopyOfDoorOpen(BufferedImage from, BufferedImage to) {
		super(from, new BufferedImage(to.getWidth(), to.getHeight(), BufferedImage.TYPE_INT_ARGB));
		this.buffer = to;
	}

	@Override
	public void animate() {
			
		this.currentFrame++;
		
		float x1 = this.overlay.getWidth() - this.overlay.getWidth() * this.currentFrame / Animator.MAX_FRAMES;
		
		float x2 = -this.overlay.getWidth()/2 + this.overlay.getWidth() * this.currentFrame / Animator.MAX_FRAMES;
		
		if(x1 < this.overlay.getWidth()/2)
			return;
		
		float variableWidth	= x2 + this.overlay.getWidth()/2;
		
		float x1pos = Math.abs(x2)+1;
		float x2pos = this.overlay.getWidth() +x2 - 1;
		
		
		System.out.println("this.currentFrame = "+this.currentFrame+", x1 = "+x1+", x2= "+x2+", " +
				"width = "+this.overlay.getWidth()/2+", variableWidth = "+variableWidth+",x1posh = "+x1pos+", x2pos = "+x2pos);
		
		
		if(x1 >= this.overlay.getWidth()/2)
		{
			/* Middle to left -----<<<<<< */
			
			Graphics g = this.overlay.getGraphics();
			Rectangle2D r2d = new Rectangle2D.Float(x1pos, this.overlayPosition.y, variableWidth, this.overlay.getHeight());
			g.setClip(r2d);
			g.drawImage(this.buffer, 0, 0, null);
			g.dispose();
			/* Middle to right --->>>> */
			
			
			Graphics g1 = this.overlay.getGraphics();
			Rectangle2D r2d1 = new Rectangle2D.Float(x2pos, this.overlayPosition.y, variableWidth, this.overlay.getHeight());
			g1.setClip(r2d1);
			g1.drawImage(this.buffer, 0, 0, null);
			g1.dispose();
			
		}
		
	}

}
